// pages/my/my_index.js

var app = getApp();
const loginPageUrl = require('../../config').loginPageUrl

Page({
    /**
     * 页面的初始数据
     */
    data: {
        sessionId: '',
        userInfo: { 
            avatarUrl:'/images/icon-avatar.png',
            nickName:'',
        },
        orderInfo:{}
    },
    toMyAccount: function() {
  
        wx.navigateTo({
            url: this.data.sessionId ? '/pages/my_account/index' : loginPageUrl,
        })
        
    },
    onLoad: function (options){

    },
    onShow: function(){
        this.loadUserData();
    },
    toOrderList: function(){
        wx.navigateTo({
            url: this.data.sessionId ? '/pages/my_order_list/index' : loginPageUrl,
        })
    },
    loadUserData: function(){
        var that = this;
        var sessionId = wx.getStorageSync('sessionId')
        if (sessionId) {
            that.setData({
                sessionId: sessionId,
                userInfo: app.globalData.userInfo
            });

            console.info("发起请求")
            app.WxRequest
                .getRequest('/users/skyvow/repos')
                .then(res => {
                    that.setData({
                        orderInfo: {
                            dfkNum: 1,
                            dshNum: 5
                        }
                    })
                })

        } else {
            this.setData({
                sessionId: '',
                userInfo: {
                    avatarUrl: '/images/icon-avatar.png',
                },
                orderInfo: {}
            });
        }
    }
})